#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <cstdbool>
#include <unistd.h>
using namespace std;

//我的系统自定义的环境变量表
const int envnum=64;
char* genv[envnum];

//全局命令行参数表
const int gargvnum=64;
char* gargnum[gargvnum];

//全局当前工作路径
const int basesize=1024;
char pwd[basesize];

//上一命令错误返回值
int lastcode;

string GetUser(){
    string name=getenv("USER");
    return name.empty()?"None":name;
}

string GetHostName(){
    string hostname=getenv("HOSTNAME");
    return hostname.empty()?"None":hostname;
}

string GetPwd(){
    if(nullptr==getcwd(pwd,sizeof(pwd)))
        return "None";
    
    putenv(pwd);
    return pwd;
}

string LastDir(){
    string curr=GetPwd();
    if(curr=="/"||curr=="None")
        return curr;

    size_t pos=curr.rfind('/');
    if(pos==string::npos)
        return curr;
    return curr.substr(pos+1);

}
    
//string MakeCommand(){
//    char command[basesize];
//    snprintf(command,basesize,"[%s@%s %s]#",
//            GetUser().c_str(),GetHostName().c_str(),LastDir().c_str());
//
//    return command;
//}

void PrintCommand(){
    
    printf("[%s@%s %s]#",
            GetUser().c_str(),GetHostName().c_str(),LastDir().c_str());
}

//bool GetCommand(char* command__buffer,int size){
//
//}
//
//
//void ParseCommand(char* command_buffer,int len){
//
//}
//
//bool CheckAndBuiltCommand(){
//
//}
//
//is_void ExecuteCommand(){
//
//}
int main(){
    while(1){
        PrintCommand();
//        if(!GetCommand(command__buffer,basesize)){
//            continue;
//        }
//        ParseCommand(command_buffer,strlen(command_buffer));
//        if(CheckAndBuiltCommand()){
//            continute;
//        }
//        ExecuteCommand();

    }
    return 0;
}
